//二分查找
#include <stdio.h>
int binarySearch(int *a, int item, int low, int high) //参数传入:数组地址 查找元素 下标低位 下标高位
{
    int mid = 0; //mid为指向下标
    int guess = 0; //mid为指向下标的元素
    while (low <= high)
    {
        mid = (low + high) / 2; //二分查找
        guess = a[mid];
        if (guess == item) //找到目标元素
        {
            return mid;
        }
        if (guess > item) //目标元素在右边
        {
            high = mid - 1;
        }
        if (guess < item) //目标元素在左边
        {
            low = mid + 1;
        }
    }
    return -1;
}

int main()
{
    int s[10] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};
    int flag = binarySearch(s, 11, 0, 9);
    if (flag == -1)
    {
        printf("查无此项");
    }
    else
    {
        printf("在第%d个位置找到,下标为[%d]", flag + 1, flag);
    }
}